import React, { useEffect } from "react";
import { useSelector, useDispatch } from "react-redux";
import { useNavigate } from "react-router-dom";
const BaiduMapRedirect = () => {
  const navigate = useNavigate();
  const dispatch = useDispatch();
  useEffect(() => {
    // 创建地图实例
    let map = new window.BMapGL.Map("container");
    // 设置中心点坐标
    let point = new window.BMapGL.Point(116.404, 39.915);
    // 地图初始化,设置中心点坐标和地图级别
    map.centerAndZoom(point, 15);
    map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
    let scaleCtrl = new window.BMapGL.ScaleControl(); // 添加比例尺控件
    map.addControl(scaleCtrl);
    let zoomCtrl = new window.BMapGL.ZoomControl(); // 添加缩放控件
    map.addControl(zoomCtrl);
    let cityCtrl = new window.BMapGL.CityListControl(); // 添加城市列表控件
    map.addControl(cityCtrl);
    // 监听地图的单击事件
    map.addEventListener("click", function (e) {
      console.log(e.latlng, "经纬度latlng");
      // 标注位置并跳回添加楼层页面
      navigate("/home/propertiesforsale/propertymanagement/addaproperty", {
        state: { latlng: e.latlng },
      });
    });
  }, []);
  // 百度地图经纬度
  const latitude = 39.908722;
  const longitude = 116.397496;

  return <div id="container" style={{ width: "100%", height: "100%" }}></div>;
};

export default BaiduMapRedirect;
